<?php
declare (strict_types=1);

namespace app\common\model;

class Collect extends Base
{
    protected $name = 'collect';


    public static function setCollect($pid,$type,$uid){
        parent::startTrans();
        try {
            $find=parent::where(['delete_time'=>0,'uid'=>$uid,'pid'=>$pid])->find();


            if($find){
                $find->delete(true);
            }
            if($type==1)
            {
                $data['uid'] = $uid;
                $data['pid'] = $pid;
                parent::create($data);

                parent::commit();
                return ['code' => 1,'msg' => '收藏成功'];
            }else{
                parent::commit();
                return ['code' => 1,'msg' => '取消收藏成功'];
            }

        } catch (\Exception $e) {
            return ['code' => -1, 'msg' => $e->getMessage()];
        }
    }


}
